package com.woniuxy.profile.service.impl;

import com.woniuxy.commons.dto.BrowseDto;
import com.woniuxy.commons.dto.ScheduleDto;
import com.woniuxy.commons.entity.Browse;
import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.entity.Schedule;
import com.woniuxy.profile.mapper.ScheduleMapper;
import com.woniuxy.profile.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: dengzj
 * @Description:
 * @Date: Created in 10:09 2020/7/30
 */
@Service
public class ScheduleServiceImpl implements ScheduleService {
    @Autowired
    private ScheduleMapper scheduleMapper;


    @Override
    public PageBean<Schedule> findSchedule(ScheduleDto scheduleDto, int page) {
        PageBean<Schedule> schedulePageBean=new PageBean<>();
        int index=(page-1)*8;
        scheduleDto.setIndex(index).setPageSize(8);
        //System.out.println(uid);
        List<Schedule> data=scheduleMapper.findSchedule(scheduleDto);
        int totalNum=scheduleMapper.countOfSchedule(scheduleDto.getUid());
        schedulePageBean.setData(data);
        schedulePageBean.setTotalNum(totalNum);
        schedulePageBean.setTotalPage(totalNum % 8 == 0 ? totalNum / 8 : totalNum / 8 + 1);
        schedulePageBean.setNumsOfCurrPage(data.size());
        schedulePageBean.setPage(page);
        schedulePageBean.setPageSize(8);
        return schedulePageBean;
    }

    @Override
    public PageBean<Browse> findBrowse(BrowseDto browseDto, int page) {
        PageBean<Browse> browsePageBean=new PageBean<>();
        int index=(page-1)*8;
        browseDto.setIndex(index).setPageSize(8);
        List<Browse> data=scheduleMapper.findBrowse(browseDto);
        int totalNum=scheduleMapper.countOfBrowse(browseDto.getUid());
        browsePageBean.setData(data);
        browsePageBean.setTotalNum(totalNum);
        browsePageBean.setTotalPage(totalNum % 8 == 0 ? totalNum / 8 : totalNum / 8 + 1);
        browsePageBean.setNumsOfCurrPage(data.size());
        browsePageBean.setPage(page);
        browsePageBean.setPageSize(8);
        return browsePageBean;
    }

    @Override
    public List<ScheduleDto> rankingOfStudyTime(ScheduleDto scheduleDto) {

        return scheduleMapper.findStudyTime(scheduleDto);
    }
}
